﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class admin_cms_default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["timeout"] == null)
            {
                Response.Redirect("login.aspx");
            }
            else
            {
                  Load_Footer();
            }
          
            
        }

    }
    protected void Load_Footer()
    {
        DataTable dtfooter = new DataTable();

        dtfooter = DataAccess.ExeSQLToDataTable("select * from Footer");

        if (dtfooter.Rows.Count > 0)
        {
            GridView1.DataSource = dtfooter;
            GridView1.DataBind();
        }
    }
    protected void bt_delete_yahoo(object sender, EventArgs e)
    {

    }

    protected void grv_yahoo_click(object sender, CommandEventArgs e)
    {

        string Id = e.CommandArgument.ToString();
        string CheckName = e.CommandName.ToString();
        if (CheckName == "X")
        {

            DataAccess.ExeNonSQL("delete from Footer where Id='"+Id+"'");
            Response.Write("<script>alert('Bạn xóa thành công 1 bản ghi')</script>");
            Load_Footer();
        }
        else
        {
            DataTable dtgrv_footer= new DataTable();
            dtgrv_footer = DataAccess.ExeSQLToDataTable("select * from Footer");
            if (dtgrv_footer.Rows.Count > 0)
            {
                txtname.Value = dtgrv_footer.Rows[0][1].ToString();
                txtcopy.Text = dtgrv_footer.Rows[0][2].ToString();
               
                Session.Add("Id", Id);
            }
        }
    }
    protected void Footer_Insert(object sender, EventArgs e)
    {
        string footer = txtname.Value;
        string copy = txtcopy.Text;

        DataAccess.ExeNonSQL("Insert into Footer(content,copy) values(N'"+footer+"',N'"+copy+"')");
        Response.Write("<script>alert('Bạn thêm thành công 1 bản ghi')</script>");
        Load_Footer();

    }
    protected void Footer_update(object sender, EventArgs e)
    {
        int Id = Convert.ToInt32(Session["Id"].ToString());
        string footer = txtname.Value;
        string copy = txtcopy.Text;

        DataAccess.ExeNonSQL("Update Footer set content=N'"+footer+"',copy=N'"+copy+"' where Id='"+Id+"'");
        Response.Write("<script>alert('Bạn sửa thành công 1 bản ghi')</script>");
        Load_Footer();
    }
}
